import sqlite3
from flask import jsonify

#insert data to DB.
def get_db():
    conn = sqlite3.connect('reviews.db')
    cursor = conn.cursor()
    # 创建表
    create_table_sql = """
        CREATE TABLE IF NOT EXISTS reviews (
            id INTEGER PRIMARY KEY,
            content TEXT,
            score INTEGER,
            category TEXT,
            region TEXT,
            sentiment TEXT
        );
        """
    cursor.execute(create_table_sql)
    conn.commit()  # 提交事务

    # 插入一些示例数据
    insert_data_sql = """
        INSERT INTO reviews (id,content, score, category, region, sentiment)
        VALUES 
        (1,'这家店的环境非常好，服务也很周到，菜品味道更是一流！', 5, '中餐', '北京', '正面'),
        (2,'菜品口味太一般了，没什么特色，价格还贵。', 2, '西餐', '上海', '负面');
        """
    cursor.execute(insert_data_sql)
    conn.commit()  # 提交事务
    cursor.execute('SELECT sentiment, COUNT(*) FROM reviews GROUP BY sentiment')
    data = {row[0]: row[1] for row in cursor.fetchall()}
    print("这是output: "+jsonify(data))
    conn.row_factory = sqlite3.Row
    return conn
def main():
    conn = get_db()
    cursor = conn.cursor()
    print("这是主函数的内容。")

if __name__ == "__main__":
    main()